package com.yanyeori.framework.web.http.request.feign;

import com.netflix.hystrix.strategy.HystrixPlugins;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * 自定义的hystrix 线程策略
 *
 * @author chenkuan 2021/8/2
 */
@Configuration
@ConditionalOnClass(name = "feign.RequestInterceptor")
public class FeignRequestConfig {

    @Bean
    @ConditionalOnMissingBean(name = "feignRequestInterceptor")
    public FeignRequestInterceptor feignRequestInterceptor() {
        return new FeignRequestInterceptor();
    }

    @PostConstruct
    public void registerConcurrencyStrategy() {
        HystrixPlugins.getInstance().registerConcurrencyStrategy(new MyHystrixConcurrencyStrategy(feignRequestInterceptor()));
    }
}
